<?php
class Area extends BaseMongoDocument
{
    public $name;
    public $about;
    
    public function getCollectionName()
    {
        return 'area';
    }
    
    /**
	 * Returns the static model of the specified AR class.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
    
    public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name', 'required'),
            array('ctime, mtime, about', 'safe'),
		);
    }
    
    public function attributeLabels()
    {
        return array(
            'name'=> '区域名称',
            'about'=>'备注',
        );
    }
    
    public function getName()
    {
        return $this->name;
    }
    
    public function getAll($returnMongoCursor=false)
    {
        $criteria = new EMongoCriteria;
        $criteria->setUseCursor($returnMongoCursor);
        $criteria->setSort(array('ctime'=>EMongoCriteria::SORT_DESC));
        
        return Area::model()->findAll($criteria);
    }
    
    public function beforeSave()
    {
        if(parent::beforeSave())
        {
            
            return true;
        }
        else
            return false;
    }


    public function getAllArea()
    {
        return self::model()->findAllByAttributes(array(
            '_id',
            'name',
        ));
    }
}
